package com.acme.bankapp.service.bank;

import com.acme.bankapp.domain.bank.Bank;
import com.acme.bankapp.domain.client.Client;
import com.acme.bankapp.domain.client.ClientRegistrationListener;
import com.acme.bankapp.domain.exception.ClientExistsException;
import com.acme.bankapp.domain.bank.Bank.*;


public class BankService {
	
	static public void addClient(Bank bank, Client client) throws ClientExistsException{
		bank.addClient(client);
	}
	
	static public boolean isAClietnOfBank(Bank bank,Client client){
		return bank.getClient(client) != null ? true : false;
	}
	
	static public Bank createNewBank(){
		return new Bank();
	}
	
	static public Bank createNewBankWithLisners(){
		return new Bank(clientRegistrationListenersCreator());
	}
	
	 private static ClientRegistrationListener[] clientRegistrationListenersCreator() {
         return new ClientRegistrationListener[]{new DebugListener(), new EmailNotificationListener(), new PrintClientListener()};
	 }
	
	
	static public void printBalance(Bank bank){
		for (Client client : bank.getClients()) {
			if(client == null)
				continue;
			System.out.println(client);
		}
		
	}
	
	static public void printMaximumAmountToWithdraw(Bank bank){
		for (Client client : bank.getClients()) {
			if(client == null)
				continue;
			System.out.println("maximumAmountToWithdraw = " + client.getAccount().maximumAmountToWithdraw());
		}
	}
}
